{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9b3f9a49-79cb-4028-8440-a331dafcc40a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import torch as t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "29883ae9-bc2b-4612-91ef-5215d9a8c645",
   "metadata": {},
   "outputs": [],
   "source": [
    "N = 20\n",
    "X = t.rand(N)\n",
    "k = 2; b = 3\n",
    "Y = k * X + b + t.randn(N) * 0.02"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0b2d686d-aff1-40e0-8e6c-34a7e0fd01b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x15824b82970>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAXtElEQVR4nO3db4xc1Z3m8e9D0wwNC+kodBho45gZMd6QOPzZWsOsd5PAZrBNCBAr0ppAIqGMLGfDCI20DnhfkJnMCyfyG5RdEstCaBNFCYoS22EYwCAhlmRYCO2xwRDiyEOYwe1o3EBMILGCbZ59UbeTolzVfduu7qq6/XykkqvuPdV1jmw9fXzurd+RbSIiorpO6nYHIiJidiXoIyIqLkEfEVFxCfqIiIpL0EdEVNzJ3e5AK2eddZYXLVrU7W5ERPSNHTt2vGJ7pNW5ngz6RYsWMTY21u1uRET0DUn/0u5clm4iIiouQR8RUXEJ+oiIikvQR0RUXII+IqLievKum4iI+WTbznE2bt/D/oOHOHd4iHXLF3P9JaMd+/mlZvSSXpK0W9IuScfc96i6r0naK+lZSZc2nFshaU9x7vaO9Tw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7QO+BAzC7GRbSiBERFRcLy/dREREByToIyIqLkEfEVFxCfqIiIpL0EdEVFyCPiKi4hL0EREV9/8B0glg5LtGzf4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X, Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d11ded1d-af78-43fe-8f45-8c4443a92376",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([0.4837], requires_grad=True), tensor([1.0549], requires_grad=True))"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w_k = t.randn(1)\n",
    "w_k.requires_grad = True\n",
    "w_b = t.randn(1)\n",
    "w_b.requires_grad = True\n",
    "w_k, w_b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d4f7c4f3-5d68-4d51-97a9-d783c894e3c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x15824cabf70>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAYl0lEQVR4nO3df4xd5X3n8ffH4zv2zNhmxvYE8NjGtOu4+UEJ9K4hy+7KoVUJLlpYxB+kbVDRShbZZEWlhhbyB1XVlUgVqUpTNrhWGqWoP6KqoV6ahbJISRqS1qRjY37FZeXNJsU2igf8C3sGe2b83T/OveM7d+6de8Zz7q8zn5d0Nffe88y9z8Hmw8Nzvs95FBGYmVn3W9buDpiZW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0A/xnY3cJ+NVOaP+f3A0OSviNpv6T7Wta75khzzo8DHyDZT+FV4MGIuNia7rVF5vmVZpPodkmzE1Lq3ZK6ROrzkfQxkkD/903tUfOlOecvAr8TEdPJ4K3rpTnn5cAvAL8I9AH/JGlfRPyfZneuSdKc823AQeBW4GeB5yW9EBFnmty3dsk8vzo50NPshJS33ZJSnY+knwe+AtweEe+0qG/Nkuaci8DXS2G+HtgpaSoi9rakh9lL+3f77Yg4B5yT9F3geqBbAz3NOd8PfD6SCebDkv4f8HPAD1rTxZbLPL86ecrln4Gtkq6V1AvcS7I7UqW87ZbU8JwlbQaeAj7ZxaO1Sg3POSKujYgtEbEF+Bvgv3ZxmEO6v9v/E/gPkpZL6gduAg61uJ9ZSnPO/0ryfyRIuhLYBvyopb1srczzq2NH6BExJekzwHMkV8i/GhGvS3qgdDx3uyWlPOdHgXXAl0sj1qno4jvVpTznXElzzhFxSNLfA68AF4GvRETN8rdukPLP+feBr0l6lWQ64nciomtvq9uO3d689N/MLCc6ecrFzMwWwIFuZpYTDnQzs5xwoJuZ5YQD3cwsJxzoZmY54UA3M8uJ/w+1ccz7sbpA9AAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "test_x = t.linspace(0, 1, 100)\n",
    "test_y = test_x * w_k.detach() + w_b.detach()\n",
    "plt.plot(test_x, test_y)\n",
    "plt.scatter(X, Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1c901559-d973-4e05-af25-9c4816a93dcb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor(7.1135, grad_fn=<MeanBackward0>)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_hat = w_k * X + w_b\n",
    "loss = ((y_hat - Y)**2).mean()\n",
    "loss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "887726b5-4c53-4c70-a728-a8effe1fdde5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([1.2179, 1.2592, 1.3736, 1.4203, 1.2635, 1.2339, 1.3003, 1.1922, 1.2782,\n",
       "        1.1451, 1.4266, 1.0652, 1.2733, 1.1743, 1.1502, 1.3459, 1.1865, 1.5306,\n",
       "        1.5378, 1.1174], grad_fn=<AddBackward0>)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_hat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a940c0ba-64c6-47db-9071-9e674abfdab3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(None, None)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w_k.grad, w_b.grad"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1d50ff88-44b7-49a3-81fb-8830ee83c1df",
   "metadata": {},
   "outputs": [],
   "source": [
    "loss.backward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "d88547e3-4165-412d-bd01-0aa34dd1e939",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([0.4837], requires_grad=True), tensor([1.0549], requires_grad=True))"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w_k, w_b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7b61c80c-1f9b-4f54-a5e2-2ce6c9969412",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([-2.6059]), tensor([-5.2742]))"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w_k.grad, w_b.grad"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "deb7bbfd-e4b1-4369-b8ee-fd1dc7c81197",
   "metadata": {},
   "outputs": [],
   "source": [
    "lr = 0.05"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "eab71a01-3a90-4d13-9508-8dc1cab69eb2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([0.4837], requires_grad=True), tensor([1.0549], requires_grad=True))"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w_k, w_b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "78d160a4-56bf-4a7b-bda4-2a4ab273ce49",
   "metadata": {},
   "outputs": [],
   "source": [
    "w_k.data = w_k.data - lr * w_k.grad.data\n",
    "w_b.data = w_b.data - lr * w_b.grad.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "5aab5e16-46d2-4b1e-ac20-f6dc93282ee5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([0.6140], requires_grad=True), tensor([1.3186], requires_grad=True))"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w_k, w_b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "112611d3-ba92-4afb-9328-1d346cacfbd4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x15824e08220>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAYFklEQVR4nO3dfWxd913H8fcnjhM7TWy3tVO7Ttx0IxTWZX3g0ge6oVDG2oaK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Tdkj5ct+pqI8k+Pwr8NHAQeAW4PyLO1Ke8hkg9v5r5JtEq817pHMskY1pJ4v2R9AvkA/29Na2o9pLs82eBP4iI6fzBW8tLss/LgZ8BfhHoBP5d0nMR8d+1Lq5GkuzzLcCLwM3AO4GnJT0bEWM1rq1RUs+vZg70/cD6otfryP/LvdAxrSTR/kh6D/BF4LaIeKtOtdVKkn3OAY8XwrwX2CJpKiJ21qXC9CX9u300It4G3pb0DHAV0KqBnmSf7wU+E/kG8z5JPwB+CviP+pRYd6nnVzO3XP4T2CjpckkrgHuAJ0rGPAF8uHC2+AZgNCIO1bvQFFXdZ0lDwA7gQy18tFas6j5HxOURsSEiNgBfAX67hcMckv3d/jrwPknLJa0Crgf21rnONCXZ5/8j/z8SJF0CXAF8v65V1lfq+dW0R+gRMSXpY8BT5M+QfykiXpN0X2H7NvIzHrYA+4CT5P+Fb1kJ9/mTwMXA5wtHrFPRwleqS7jPmZJknyNir6R/Bl4GzgBfjIiy099aQcI/5z8C/lrSK+TbEX8QES17WV1Jfw9sBnol7Qc+BbRD7fLLS//NzDKimVsuZma2AA50M7OMcKCbmWWEA93MLCMc6GZmGeFANzPLCAe6mVlG/D9AabQpq8iGZgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "test_x = t.linspace(0, 1, 100)\n",
    "test_y = test_x * w_k.detach() + w_b.detach()\n",
    "plt.plot(test_x, test_y)\n",
    "plt.scatter(X, Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "2735d27f-206d-4aac-b940-4777562aa8bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "w_b.grad.data = t.zeros(1)\n",
    "w_k.grad.data = t.zeros(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "80776b19-b188-4af3-aaa1-2bd2aa2e4a1c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([0.6140], requires_grad=True), tensor([1.3186], requires_grad=True))"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w_k, w_b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "17e959b5-db30-4a59-b6b8-2f591d69848d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([0.]), tensor([0.]))"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w_k.grad, w_b.grad"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "7a275e7b",
   "metadata": {},
   "outputs": [],
   "source": [
    "lr = 0.02\n",
    "for i in range(10):\n",
    "    # clear grad\n",
    "    # calc y_hat\n",
    "    # calc loss\n",
    "    # backward\n",
    "    # update grad\n",
    "    # update w_k, w_b\n",
    "    pass"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
